﻿Imports System.Data
Imports VSModel
Imports Cls_Common

Partial Class Control_Product_Detail
    Inherits System.Web.UI.UserControl
#Region "Sub and Function "
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If Not Request.QueryString("Productid").ToString.Equals("0") Then
                hidID.Value = Request.QueryString("Productid")
                ShowData()
            End If
        End If
    End Sub
    Protected Sub ShowData()
        Using data As New VSEntities
            Dim p As Product = (From q In Data.Products Where q.ProductId = hidID.Value Select q).SingleOrDefault
            If Not p Is Nothing Then
                lblTitle.Text = IIf(IsNothing(p.Title) = True, "", p.Title)
                lblQuerystring.Text = IIf(IsNothing(p.QueryString) = True, "", p.QueryString)
                lblDescription.Text = IIf(IsNothing(p.Description) = True, "", p.Description)
                lblImagepreview.ImageUrl = IIf(IsNothing(p.ImagePreview) = True, "", p.ImagePreview)
                lblOriginalprice.Text = IIf(IsNothing(p.OriginalPrice) = True, "", FormatNumber(p.OriginalPrice))
                lblSellprice.Text = IIf(IsNothing(p.SellPrice) = True, "", FormatNumber(p.SellPrice))
                lblStoreid.Text = IIf(IsNothing(p.StoreId) = True, "", p.Store.Title)
                lblViewed.Text = IIf(IsNothing(p.Viewed) = True, "", p.Viewed)
                lblCreated.Text = IIf(IsNothing(p.Created) = True, "", Convert.ToDateTime(p.Created).ToString("dd/MM/yyyy"))
                If Not p.CreatorId Is Nothing Then
                    Dim t = (From h In data.Users Where h.UserId = p.CreatorId Select h).FirstOrDefault
                    If Not t Is Nothing Then
                        lblCreatorid.Text = t.UserName
                    End If
                End If
                If Not p.ModifierId Is Nothing Then
                    Dim t = (From h In data.Users Where h.UserId = p.ModifierId Select h).FirstOrDefault
                    If Not t Is Nothing Then
                        lblModifierid.Text = t.UserName
                    End If
                End If

                lblModified.Text = IIf(IsNothing(p.Modified) = True, "", Convert.ToDateTime(p.Modified).ToString("dd/MM/yyyy"))
                lblIsselloff.Checked = IIf(IsNothing(p.IsSellOff) = True, False, p.IsSellOff)
                lblIshot.Checked = IIf(IsNothing(p.IsHot) = True, False, p.IsHot)
                lblStatusid.Text = IIf(IsNothing(p.StatusId) = True, "", p.Status.Title)
                lblBeffectivedate.Text = IIf(IsNothing(p.bEffectiveDate) = True, "", Convert.ToDateTime(p.bEffectiveDate).ToString("dd/MM/yyyy"))
                lblPublisheddate.Text = IIf(IsNothing(p.PublishedDate) = True, "", Convert.ToDateTime(p.PublishedDate).ToString("dd/MM/yyyy"))
                lblEeffectivedate.Text = IIf(IsNothing(p.eEffectiveDate) = True, "", Convert.ToDateTime(p.eEffectiveDate).ToString("dd/MM/yyyy"))
            End If
        End Using
    End Sub
#End Region
End Class
